/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.venta;

import Controller.OcurrenciaC;
import Model.OcurrenciaM;
import Util.ArrayListTableModel;
import Util.MiRenderBoton;
import java.awt.Color;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Maryluz
 */
public class frmOcurrencias extends javax.swing.JDialog {

    /**
     * Creates new form frmOcurrencias
     */
    int editar = 0;
    OcurrenciaM ocu;
    int xIdTienda;
    
    public frmOcurrencias(java.awt.Frame parent, boolean modal,int idTiendaa) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        setResizable(false);
        txtFecha.setFormats(" dd/MM/yyyy");
        txtFechaFiltro.setFormats(" dd/MM/yyyy");
        txtOcurrencia.requestFocus();
        buttonGroup1.add(rbt_todo);
        buttonGroup1.add(rbt_fecha);
        rbt_todo.setSelected(true);
        txtmensaje.setText("");
        configurarTabla();
        xIdTienda=idTiendaa;
        tb_Ocurrencias.setRowHeight(35);
        cargarTabla();
        ocu= new OcurrenciaM();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtOcurrencia = new javax.swing.JTextArea();
        btnRegistrar = new javax.swing.JButton();
        btnNuevo = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtFecha = new org.jdesktop.swingx.JXDatePicker();
        btnEditar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tb_Ocurrencias = new javax.swing.JTable();
        rbt_todo = new javax.swing.JRadioButton();
        rbt_fecha = new javax.swing.JRadioButton();
        txtFechaFiltro = new org.jdesktop.swingx.JXDatePicker();
        txtmensaje = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ocurrencias");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Ocurrencia :");

        txtOcurrencia.setEditable(false);
        txtOcurrencia.setColumns(20);
        txtOcurrencia.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtOcurrencia.setRows(5);
        jScrollPane1.setViewportView(txtOcurrencia);

        btnRegistrar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnRegistrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Save.png"))); // NOI18N
        btnRegistrar.setText("  GUARDAR");
        btnRegistrar.setEnabled(false);
        btnRegistrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegistrarActionPerformed(evt);
            }
        });

        btnNuevo.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/url_historial.png"))); // NOI18N
        btnNuevo.setText("  NUEVO");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Fecha de Registro :");

        txtFecha.setEditable(false);

        btnEditar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/registro.png"))); // NOI18N
        btnEditar.setText("  EDITAR");
        btnEditar.setEnabled(false);
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/remove.png"))); // NOI18N
        btnCancelar.setText(" CANCELAR");
        btnCancelar.setEnabled(false);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane1)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnNuevo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnRegistrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnCancelar)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRegistrar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEditar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        tb_Ocurrencias.setModel(new ArrayListTableModel(
            new Object [][] {},
            new String [] {"  ID"," Fecha"," Hora","Descripción","",""}
        ) {
            Class[] types = new Class [] {
                java.lang.String.class,java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false,false,false,false,false,false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tb_Ocurrencias.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tb_OcurrenciasMouseClicked(evt);
            }
        });
        tb_Ocurrencias.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tb_OcurrenciasKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(tb_Ocurrencias);

        rbt_todo.setText("Todas");
        rbt_todo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbt_todoActionPerformed(evt);
            }
        });

        rbt_fecha.setText("Filtrar por Fecha");
        rbt_fecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbt_fechaActionPerformed(evt);
            }
        });

        txtFechaFiltro.setEnabled(false);
        txtFechaFiltro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFechaFiltroActionPerformed(evt);
            }
        });

        txtmensaje.setText("Mensaje");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtmensaje, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(rbt_todo)
                        .addGap(10, 10, 10)
                        .addComponent(rbt_fecha)
                        .addGap(18, 18, 18)
                        .addComponent(txtFechaFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(109, 109, 109)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(txtFechaFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbt_fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbt_todo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtmensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rbt_todoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbt_todoActionPerformed
        txtFechaFiltro.setEnabled(false);
        cargarTabla();
    }//GEN-LAST:event_rbt_todoActionPerformed

    private void rbt_fechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbt_fechaActionPerformed
        txtFechaFiltro.setEnabled(true);
    }//GEN-LAST:event_rbt_fechaActionPerformed

    private void btnRegistrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistrarActionPerformed

        if ("".equals(txtOcurrencia.getText().trim())) {
            JOptionPane.showMessageDialog(null, "Complete lo campos antes de guardar.");

        } else {
            if (editar != 1) {
                try {
                    OcurrenciaM oCajaM = new OcurrenciaM();
                    oCajaM.setDescOcurrencia(txtOcurrencia.getText());
                    oCajaM.setIdTienda(xIdTienda);
                    OcurrenciaC oC = new OcurrenciaC();
                    oC.agregarOcurrencia(oCajaM);
                    JOptionPane.showMessageDialog(null, "Se registro correctamente la ocurrencia.");
                    txtOcurrencia.setText("");
                    txtOcurrencia.requestFocus();

                    controles(false);
                    btnNuevo.setEnabled(true);
                    btnEditar.setEnabled(false); 
                    cargarTabla();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                
            } else {
                try {
                    OcurrenciaC oC = new OcurrenciaC();
                    ocu.setDescOcurrencia(txtOcurrencia.getText());
                    oC.actualizarOcurrencia(ocu);
                    JOptionPane.showMessageDialog(null, "Se actualizó correctamente la ocurrencia.");

                    txtOcurrencia.setText("");
                    txtOcurrencia.requestFocus();
                    controles(false);
                    btnNuevo.setEnabled(true);
                    btnEditar.setEnabled(false); 
                   
                    cargarTabla();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }



    }//GEN-LAST:event_btnRegistrarActionPerformed

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        controles(true);
        btnNuevo.setEnabled(false);
        txtOcurrencia.setText("");
        txtFecha.setDate(new Date());
        txtOcurrencia.requestFocus();
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
        btnCancelar.setEnabled(true);
        txtOcurrencia.setEditable(true);
        btnRegistrar.setEnabled(true);
        btnEditar.setEnabled(false);
        txtOcurrencia.requestFocus();
        editar = 1;
    }//GEN-LAST:event_btnEditarActionPerformed

    private void tb_OcurrenciasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tb_OcurrenciasMouseClicked


        if (evt.getClickCount() == 2) {
            int FilaSeleccionada = tb_Ocurrencias.getSelectedRow();
            if (FilaSeleccionada != -1) {
                ocu = (OcurrenciaM) tb_Ocurrencias.getValueAt(FilaSeleccionada, 5);

                SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    txtFecha.setDate(formatoDelTexto.parse(ocu.getFechaOcurrencia()));
                } catch (Exception e) {
                }
                txtOcurrencia.setText(ocu.getDescOcurrencia());
                controles(false);
                btnNuevo.setEnabled(false);
                btnEditar.setEnabled(true);
                btnCancelar.setEnabled(true);
            }
        }

        if (tb_Ocurrencias.getRowCount() != 0) {
            int columNacedora = tb_Ocurrencias.getSelectedColumn();
            if (columNacedora == 4 && tb_Ocurrencias.isEnabled()) {
                try {

                    @SuppressWarnings("UnusedAssignment")
                    OcurrenciaM oCaja = new OcurrenciaM();
                    int filaBorrada = tb_Ocurrencias.getSelectedRow();
                    oCaja = (OcurrenciaM) tb_Ocurrencias.getValueAt(filaBorrada, 5);

                    int res = JOptionPane.showConfirmDialog(this, "Usted esta borrando esta Ocurrencia !! \n¿Seguro que desea eliminarlo?", "Dialogo de Confirmación", JOptionPane.YES_NO_OPTION);
                    if (res == JOptionPane.YES_OPTION) {
                        new OcurrenciaC().borrarOcurrencia(oCaja);

                        if (tb_Ocurrencias.getRowCount() != 0) {
                            ArrayListTableModel dtm = (ArrayListTableModel) tb_Ocurrencias.getModel(); //TableProducto es el nombre de mi tabla ;)
                            dtm.removeRow(filaBorrada);
                        }
                        JOptionPane.showMessageDialog(rootPane, "Se elimino el registro con exito.");
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(rootPane, "Error al eliminar el registro. Verifique.");
                    e.printStackTrace();
                }

            }
            cargarTabla();
        }
    }//GEN-LAST:event_tb_OcurrenciasMouseClicked

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        controles(false);
        btnNuevo.setEnabled(true);
        btnEditar.setEnabled(false);
        txtOcurrencia.setText("");
        txtFecha.setDate(new Date());
        editar = 0;
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void tb_OcurrenciasKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tb_OcurrenciasKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_tb_OcurrenciasKeyReleased

    private void txtFechaFiltroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFechaFiltroActionPerformed
       
         DateFormat fechaHora = new SimpleDateFormat("yyyy-MM-dd");
        String convertido = fechaHora.format(txtFechaFiltro.getDate());
        OcurrenciaC oC = new OcurrenciaC();
        List<OcurrenciaM> oMs = oC.listarOcurrenciaFecha(convertido,xIdTienda);
        @SuppressWarnings("LocalVariableHidesMemberVariable")
        ArrayList oList;
        limpiarTabla();
        if (oMs != null) {
            int size = oMs.size();
            for (int a = 0; a < size; a++) {
                oList = new ArrayList();
                String cad = "";
                int tam = 0;
                try {
                    tam = (oMs.get(a).getIdOcurrencia() + "").length();
                    cad = "00000" + oMs.get(a).getIdOcurrencia();
                    cad = cad.substring(tam - 6, tam);
                } catch (Exception e) {
                }
                oList.add("OCU" + cad);
                oList.add(oMs.get(a).getFechaOcurrencia());
                oList.add(oMs.get(a).getHoraOcurrencia());
                oList.add(" " + oMs.get(a).getDescOcurrencia());
                oList.add(oMs.get(a));
                ((ArrayListTableModel) tb_Ocurrencias.getModel()).addRow(oList);
            }
        }
        DateFormat fechaHora2 = new SimpleDateFormat("dd/MM/yyyy");
        String convertido2 = fechaHora2.format(txtFechaFiltro.getDate());
        if (tb_Ocurrencias.getRowCount() == 0) {
            txtmensaje.setText(" No se encontraron ocurrencias realizados el " + convertido2 + ".");
            txtmensaje.setForeground(Color.red);
        } else {
            txtmensaje.setText(" Se encontraron " + tb_Ocurrencias.getRowCount() + " ocurrencia(s) realizados el " + convertido2 + ".");
            txtmensaje.setForeground(Color.BLUE);
        }
    }//GEN-LAST:event_txtFechaFiltroActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JButton btnRegistrar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JRadioButton rbt_fecha;
    private javax.swing.JRadioButton rbt_todo;
    private javax.swing.JTable tb_Ocurrencias;
    private org.jdesktop.swingx.JXDatePicker txtFecha;
    private org.jdesktop.swingx.JXDatePicker txtFechaFiltro;
    private javax.swing.JTextArea txtOcurrencia;
    private javax.swing.JLabel txtmensaje;
    // End of variables declaration//GEN-END:variables

    private void configurarTabla() {
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();
        tcr.setHorizontalAlignment(SwingConstants.CENTER);

        tb_Ocurrencias.getColumnModel().getColumn(0).setCellRenderer(tcr);
        tb_Ocurrencias.getColumnModel().getColumn(1).setCellRenderer(tcr);
        tb_Ocurrencias.getColumnModel().getColumn(2).setCellRenderer(tcr);

        tb_Ocurrencias.getColumnModel().getColumn(0).setMinWidth(80);
        tb_Ocurrencias.getColumnModel().getColumn(0).setPreferredWidth(80);
        tb_Ocurrencias.getColumnModel().getColumn(0).setMaxWidth(80);
        tb_Ocurrencias.getColumnModel().getColumn(1).setMinWidth(70);
        tb_Ocurrencias.getColumnModel().getColumn(1).setPreferredWidth(70);
        tb_Ocurrencias.getColumnModel().getColumn(1).setMaxWidth(70);
        tb_Ocurrencias.getColumnModel().getColumn(2).setMinWidth(70);
        tb_Ocurrencias.getColumnModel().getColumn(2).setPreferredWidth(70);
        tb_Ocurrencias.getColumnModel().getColumn(2).setMaxWidth(70);
        tb_Ocurrencias.getColumnModel().getColumn(4).setMinWidth(40);
        tb_Ocurrencias.getColumnModel().getColumn(4).setPreferredWidth(40);
        tb_Ocurrencias.getColumnModel().getColumn(4).setMaxWidth(40);
        tb_Ocurrencias.getColumnModel().getColumn(5).setMinWidth(0);
        tb_Ocurrencias.getColumnModel().getColumn(5).setPreferredWidth(0);
        tb_Ocurrencias.getColumnModel().getColumn(5).setMaxWidth(0);


        tb_Ocurrencias.getColumnModel().getColumn(4).setCellRenderer(new MiRenderBoton(true));
    }

    private void limpiarTabla() {
        ArrayListTableModel oModelTbl = (ArrayListTableModel) tb_Ocurrencias.getModel();
        int i = oModelTbl.getRowCount();
        for (int a = 0; a < i; a++) {
            oModelTbl.removeRow(0);
        }
    }

    private void cargarTabla() {
        OcurrenciaC oC = new OcurrenciaC();
        List<OcurrenciaM> oMs = oC.listarOcurrenciaTodo(xIdTienda);
        @SuppressWarnings("LocalVariableHidesMemberVariable")
        ArrayList oList;
        limpiarTabla();
        if (oMs != null) {
            int size = oMs.size();
            for (int a = 0; a < size; a++) {
                oList = new ArrayList();
                String cad = "";
                int tam = 0;
                try {
                    tam = (oMs.get(a).getIdOcurrencia() + "").length();
                    cad = "00000" + oMs.get(a).getIdOcurrencia();
                    cad = cad.substring(tam - 6, tam);
                } catch (Exception e) {
                }


                oList.add("OCU" + cad);
                oList.add(oMs.get(a).getFechaOcurrencia());
                oList.add(oMs.get(a).getHoraOcurrencia());
                oList.add(" " + oMs.get(a).getDescOcurrencia());
                oList.add(" ");
                oList.add(oMs.get(a));
                ((ArrayListTableModel) tb_Ocurrencias.getModel()).addRow(oList);
            }
        }


        if (tb_Ocurrencias.getRowCount() == 0) {
            txtmensaje.setText(" No se encontraron ocurrencias realizados hasta la fecha.");
            txtmensaje.setForeground(Color.red);
        } else {
            txtmensaje.setText(" Se encontraron " + tb_Ocurrencias.getRowCount() + " ocurrencia(s) realizados hasta la fecha.");
            txtmensaje.setForeground(Color.BLUE);
        }
    }

    private void controles(boolean b) {
        txtOcurrencia.setEditable(b);
        btnRegistrar.setEnabled(b);
        btnCancelar.setEnabled(b);
        btnEditar.setEnabled(!b);
        txtOcurrencia.setEditable(b);
        txtOcurrencia.requestFocus();
    }
}
